package vg.com.chatonline.activity;

import vg.com.chatonline.adapter.DashboardAdapter;
import vg.com.variables.static_variables;
import android.content.Intent;
import android.graphics.AvoidXfermode;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import ce51.dunghn.chatslide.BaseActivity;
import ce51.dunghn.chatslide.SampleFragment;


import com.vg.view.login_index;
import com.vg.view.user_left;

public class DashboardActivity1 extends BaseActivity implements
		com.kds.abs.app.ActionBar.TabListener, OnPageChangeListener {

	public DashboardActivity1() {
		super(R.string.left_and_right);
	}

	private ViewPager pager;
	private com.kds.abs.app.ActionBar.Tab tab;
	kds.slm.app.SlidingFragmentActivity ac;
	com.kds.abs.app.SherlockFragmentActivity sherlock;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Toast.makeText(getApplicationContext(), "ma:" + login_index.id_static,
				Toast.LENGTH_SHORT).show();
		pager = (ViewPager) findViewById(R.id.pager);
		pager.setAdapter(new DashboardAdapter(getSupportFragmentManager()));
		pager.setOnPageChangeListener(this);
		// mViewPager.setPageMarginDrawable(R.drawable.border);
		// mViewPager.setPageMargin(16);
		/**
		 * Tạo ActionBar cho tab,bao nhiêu tab thì Ad cừng đó actionbar vào
		 * .SetTabListener : xác định vị trí của tab tương ứng với vị trí
		 * Fragment
		 * */
		View tabIndicator = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator, null);
		TextView title = (TextView) tabIndicator.findViewById(R.id.title);
		title.setText("Tin nhắn");
		ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
		icon.setImageResource(R.drawable.icon_config_tab1);

		View tabIndicator1 = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator, null);
		TextView title1 = (TextView) tabIndicator1.findViewById(R.id.title);
		title1.setText("Danh bạ");
		ImageView icon1 = (ImageView) tabIndicator1.findViewById(R.id.icon);
		icon1.setImageResource(R.drawable.icon_config_tab2);

		View tabIndicator2 = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator, null);
		TextView title2 = (TextView) tabIndicator2.findViewById(R.id.title);
		title2.setText("Tìm bạn");
		ImageView icon2 = (ImageView) tabIndicator2.findViewById(R.id.icon);
		icon2.setImageResource(R.drawable.icon_config_tab3);

		View tabIndicator3 = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator, null);
		TextView title3 = (TextView) tabIndicator3.findViewById(R.id.title);
		title3.setText("Profile");
		ImageView icon3 = (ImageView) tabIndicator3.findViewById(R.id.icon);
		icon3.setImageResource(R.drawable.icon_config_tab4);

		com.kds.abs.app.ActionBar actionBar = sherlock.getSupportActionBar();

		// actionBar.setBackgroundDrawable(R.drawable.tab_indicator);
		actionBar
				.setNavigationMode(com.kds.abs.app.ActionBar.NAVIGATION_MODE_TABS);
		tab = actionBar.newTab();
		tab.setCustomView(tabIndicator).setTabListener(this);
		actionBar.addTab(tab);
		// actionBar.addTab(actionBar.newTab().setCustomView(tabIndicator)
		// .setTabListener(this));

		actionBar.addTab(actionBar.newTab().setCustomView(tabIndicator1)
				.setTabListener(this));

		actionBar.addTab(actionBar.newTab().setCustomView(tabIndicator2)
				.setTabListener(this));

		actionBar.addTab(actionBar.newTab().setCustomView(tabIndicator3)
				.setTabListener(this));
		// getSupportActionBar().setDisplayShowHomeEnabled(false);
		// getSupportActionBar().setDisplayShowTitleEnabled(false);

		// actionBar.addTab(actionBar.newTab().setText("Other")
		// .setTabListener(this));
		// actionBar.addTab(actionBar.newTab().setText("Contact1")
		// .setTabListener(this));
		/**
		 * Trả về vị trí của TabBar
		 */
		actionBar.setSelectedNavigationItem(1);
		sherlock.getSupportActionBar().setIcon(R.drawable.menu11);
		sherlock.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		// getSupportActionBar().setTitle("Để Được Yêu");
		// getSupportActionBar().setBackgroundDrawable(d)
	}

	public void onPageScrolled(int arg0, float arg1, int arg2) {
		// TODO Auto-generated method stub

	}

	public void onPageSelected(int arg0) {
		// TODO Auto-generated method stub
		/**
		 * Vị trí Page được chọn khi có sự thay đổi
		 * */
		sherlock.getSupportActionBar().setSelectedNavigationItem(arg0);
	}

	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		// TODO Auto-generated method stub
		super.onCreateContextMenu(menu, v, menuInfo);
	}

	// @Override
	// public boolean onMenuItemSelected(int featureId,
	// MenuItem item) {
	// int itemId = item.getItemId();
	// switch (itemId) {
	// case android.R.id.home:
	// if (menu != null) {
	// menu.toggle();
	// Log.i("menu:", "ok");
	// }
	// Intent i=new Intent(getApplicationContext(), user_left.class);
	// break;
	// }
	// return true;
	// }

	public boolean onOptionsItemSelected(com.kds.abs.view.MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// sideNavigationView.toggleMenu();
			Intent i = new Intent(getApplicationContext(), user_left.class);
			startActivity(i);
			break;

		default:
			return sherlock.onOptionsItemSelected(item);
		}
		return true;
	}

	public void onPageScrollStateChanged(int arg0) {
		// TODO Auto-generated method stub

	}

	public void onTabReselected(com.kds.abs.app.ActionBar.Tab arg0,
			FragmentTransaction arg1) {
		// TODO Auto-generated method stub

	}

	public void onTabSelected(com.kds.abs.app.ActionBar.Tab arg0,
			FragmentTransaction arg1) {
		// TODO Auto-generated method stub
		pager.setCurrentItem(tab.getPosition());
	}

	public void onTabUnselected(com.kds.abs.app.ActionBar.Tab arg0,
			FragmentTransaction arg1) {
		// TODO Auto-generated method stub

	}

}
